﻿Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

'TODO: Enable chkCopyTo and cboDrive when 'copy to mp3 player' implemented.

Public Class OptionsDialog

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Select Case cboQuality.SelectedIndex
            Case 0
                My.Settings.Quality = InterpolationMode.HighQualityBicubic
            Case 1
                My.Settings.Quality = InterpolationMode.High
            Case 2
                My.Settings.Quality = InterpolationMode.Default
            Case 3
                My.Settings.Quality = InterpolationMode.Low
        End Select

        Select Case cboSizing.SelectedIndex
            Case 0
                My.Settings.StretchImage = False
            Case 1
                My.Settings.StretchImage = True
        End Select

        My.Settings.MP3Drive = TryCast(cboDrive.SelectedItem, String)
        My.Settings.RotateImages = chkRotate.Checked
        My.Settings.CopyImages = chkCopyTo.Checked
        My.Settings.Path = txtPath.Text
        My.Settings.Save()
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub OptionsDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboDrive.Enabled = False
        Me.Icon = My.Resources.ProgramIcon

        My.Settings.Reload()
        txtPath.Text = My.Settings.Path
        chkRotate.Checked = My.Settings.RotateImages
        chkCopyTo.Checked = My.Settings.CopyImages

        Select Case My.Settings.Quality
            Case InterpolationMode.HighQualityBicubic
                cboQuality.SelectedIndex = 0
            Case InterpolationMode.High
                cboQuality.SelectedIndex = 1
            Case InterpolationMode.Default
                cboQuality.SelectedIndex = 2
            Case InterpolationMode.Low
                cboQuality.SelectedIndex = 3
            Case Else
                cboQuality.SelectedIndex = 0
        End Select

        Select Case My.Settings.StretchImage
            Case False
                cboSizing.SelectedIndex = 0
            Case True
                cboSizing.SelectedIndex = 1
            Case Else
                cboSizing.SelectedIndex = 0
        End Select

        For Each drive_info As DriveInfo In DriveInfo.GetDrives()
            cboDrive.Items.Add(drive_info.Name)
        Next drive_info
        cboDrive.SelectedIndex = 0
        cboDrive.SelectedItem = TryCast(My.Settings.MP3Drive, Object)
    End Sub

    Private Sub chkCopyTo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCopyTo.CheckedChanged
        cboDrive.Enabled = chkCopyTo.Checked
        txtPath.Enabled = Not chkCopyTo.Checked
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Dim dlgBrowse As New FolderBrowserDialog
        dlgBrowse.SelectedPath = txtPath.Text
        If dlgBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtPath.Text = dlgBrowse.SelectedPath
        End If
    End Sub

End Class
